/*
 * VistaCalificacion.java
 *
 * Created on 28 de mayo de 2009, 07:50 PM
 */
package Matricula_Nota;

import javax.swing.JOptionPane;

/**
 *
 * @author  Pedro A. Anaya Avila
 */
//ventanas modales
public class VistaIngresoNota extends javax.swing.JDialog {

    Coordinador coordinador = new Coordinador();
    Alumno alumno;
    Seccion seccion;
    Curso curso;
    Profesor profesor;
    boolean editable;

    /** Creates new form VistaCalificacion */
    public VistaIngresoNota(javax.swing.JDialog parent, boolean modal, Alumno alumno,
            Seccion seccion, Curso curso, Profesor profesor, Coordinador coordinador, boolean editable) {

        super(parent, modal);
        initComponents();

        this.coordinador = coordinador;
        this.seccion = seccion;
        this.curso = curso;
        this.profesor = profesor;
        this.alumno = alumno;
        this.editable = editable;
        if (editable) {
            mostrarCalificacion();
        }
    }

    private void mostrarCalificacion() {
        Nota nota = coordinador.getNotaCurso(alumno, seccion, curso);
        if (nota != null) {
            txtP1.setText(String.valueOf(nota.getPractica1()));
            txtP2.setText(String.valueOf(nota.getPractica2()));
            txtEP.setText(String.valueOf(nota.getExParcial()));
            txtEF.setText(String.valueOf(nota.getExFinal()));
            txtNF.setText(String.valueOf(nota.getNotaFinal()));
            txtP1.requestFocusInWindow();
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel3 = new javax.swing.JPanel();
        jLabel6 = new javax.swing.JLabel();
        txtNF = new javax.swing.JTextField();
        txtP2 = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        txtEP = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        txtEF = new javax.swing.JTextField();
        txtP1 = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        btnAceptar = new javax.swing.JButton();
        btnCancelar = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Ingreso de Notas");

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("Registro Nota"));

        jLabel6.setText("Examen Final");

        txtNF.setEditable(false);
        txtNF.setText("00.00");

        txtP2.setText("00.00");

        jLabel4.setText("Práctica 2");

        txtEP.setText("00.00");

        jLabel5.setText("Examen Parcial");

        txtEF.setText("00.00");

        txtP1.setText("00.00");

        jLabel3.setText("Nota Final");

        jLabel12.setText("Práctica 1");

        btnAceptar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Matricula_Nota/Recursos/Accept.png"))); // NOI18N
        btnAceptar.setToolTipText("Aceptar");
        btnAceptar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAceptarActionPerformed(evt);
            }
        });

        btnCancelar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Matricula_Nota/Recursos/Cancel.png"))); // NOI18N
        btnCancelar.setToolTipText("Cancelar");
        btnCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancelarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel12)
                            .addComponent(jLabel5)
                            .addComponent(jLabel4)
                            .addComponent(jLabel6)
                            .addComponent(jLabel3))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 45, Short.MAX_VALUE)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(txtNF, javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txtEF, javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txtEP, javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txtP2, javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txtP1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 52, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                        .addComponent(btnAceptar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnCancelar)))
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtP1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel12))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtP2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtEP, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel5))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtEF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel6))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtNF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3))
                .addGap(18, 18, 18)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(btnCancelar)
                    .addComponent(btnAceptar))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnAceptarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAceptarActionPerformed
        double practica1 = Double.parseDouble(txtP1.getText());
        double practica2 = Double.parseDouble(txtP2.getText());
        double examenParcial = Double.parseDouble(txtEP.getText());
        double examenFinal = Double.parseDouble(txtEF.getText());
        if (editable) {
            coordinador.modificarCalificacion(alumno, practica1, practica2, examenParcial, examenFinal, seccion, curso, profesor);
        } else {
            try {
             coordinador.registrarCalificacion(alumno, practica1, practica2, examenParcial, examenFinal, seccion, curso, profesor);
            } catch (Exception ex) {
                JOptionPane.showMessageDialog(rootPane, ex.getMessage());
            }
        }
//        JOptionPane.showMessageDialog(rootPane, coordinador.);
//        String codigoArea = txtCodigo.getText();
//        String nombre = txtNombre.getText().trim();
//        if (!nombre.equals("")) {
//            try {
//                coordinador.modificarArea(codigoArea, nombre);
//            } catch (Exception ex) {
//                JOptionPane.showMessageDialog(rootPane, ex.getMessage());
//            }
//        }
        this.dispose();
}//GEN-LAST:event_btnAceptarActionPerformed

    private void btnCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelarActionPerformed
        // TODO add your handling code here:
        this.dispose();
}//GEN-LAST:event_btnCancelarActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAceptar;
    private javax.swing.JButton btnCancelar;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JTextField txtEF;
    private javax.swing.JTextField txtEP;
    private javax.swing.JTextField txtNF;
    private javax.swing.JTextField txtP1;
    private javax.swing.JTextField txtP2;
    // End of variables declaration//GEN-END:variables
}
